import * as client from './client'
import urlConfig from './urlConfig'
/**
 * 获取销售网点优惠策略
 */

export class VoucherRst {
    //消费者uid
    public consumerUID: string;
    //代金券状态（2-已领取,3-已使用,4-已回收）
    public voucherStatus: number[];
    //当前分页数
    public pageIndex: number;
    //每页记录数
    public pageSize: number;
}


export class VoucherRpn {
    /* "resData": {
        "pageInfo": {
          "totalCount": 1,
          "pageCount": 2
        },
        "list": [
          {
            "voucherUID": "5d85b440-4b9e-43f2-ae3b-ad48e3f01efb",
            "voucherType": 2,
            "paymentAmountThreshold": 3.0,
            "deductionValue": 4.0,
            "validTime": "2017-10-26T15:57:27.7304443+08:00",
            "expireTime": "2017-10-26T15:57:27.7304443+08:00",
            "receiveTime": "2017-10-26T15:57:27.7304443+08:00",
            "recyleTime": "2017-10-26T15:57:27.7314529+08:00",
            "validDays": 7
          },
          {
            "voucherUID": "5d85b440-4b9e-43f2-ae3b-ad48e3f01efb",
            "voucherType": 2,
            "paymentAmountThreshold": 3.0,
            "deductionValue": 4.0,
            "validTime": "2017-10-26T15:57:27.7304443+08:00",
            "expireTime": "2017-10-26T15:57:27.7304443+08:00",
            "receiveTime": "2017-10-26T15:57:27.7304443+08:00",
            "recyleTime": "2017-10-26T15:57:27.7314529+08:00",
            "validDays": 7
          }
        ]
      } */
    //优惠类型 1：无优惠；2：按比率优惠；3：满多少减多少（有上限）；4：满多少减多少（无上限）
    pageInfo: pageInfo;
    list: unit[];
}

export class pageInfo{
  public totalCount: number;
  public pageCount: number;
}

export class unit{
  public voucherUID: string;
  public voucherType: number;
  public paymentAmountThreshold: number;
  public deductionValue: number;
  public validTime: string;
  public expireTime: string;
  public receiveTime: string;
  public recyleTime: string;
  public validDays: number;
}
/**
 * 获取销售网点优惠策略
 */
export async function exec(rst: VoucherRst,userInfo: any) {
    const data = await client.exec(urlConfig.voucher, rst, userInfo);
    return JSON.parse(data) as client.RSM<VoucherRpn>;
}